import Vuex from 'vuex'
import Locale from '~/locales'

import { STORAGE_KEY } from './config'

import getters from './getters'
import mutations from './mutations'
import actions from './actions'


const NUXT_ENV_LANGUAGE = process.env.NUXT_ENV_LANGUAGE ? process.env.NUXT_ENV_LANGUAGE : "zh"

let store = () => new Vuex.Store({
  state: {
    locales: Locale(),
    locale: NUXT_ENV_LANGUAGE,
    token: '',
    userInfo: '',
  },
  getters,
  mutations,
  actions,
  set (state, {STORAGE_KEY, val}) {
    state[STORAGE_KEY] = val
  }
})

export default store
